package hlhj.fhp.checkpoint.customView

import android.content.Context
import android.graphics.*
import android.icu.util.Measure
import android.util.AttributeSet
import android.view.View

/**
 * Created by Never Fear   on 2018\12\14 0014.
Never More....
 */
class SanJiaoTextView @JvmOverloads constructor(context: Context? = null, attributeSet: AttributeSet? = null, def: Int = 0) : View(context, attributeSet, def) {

    private var mHeight=100
    private var mWidth=100
    private var mPaint:Paint?=null

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        val widthMode = MeasureSpec.getMode(widthMeasureSpec)
        val heightMode = MeasureSpec.getMode(heightMeasureSpec)
        if (widthMode==MeasureSpec.EXACTLY){
            mWidth=MeasureSpec.getSize(widthMeasureSpec)
        }
        if (heightMode==MeasureSpec.EXACTLY){
            mHeight=MeasureSpec.getSize(heightMeasureSpec)
        }
        setMeasuredDimension(mWidth,mHeight)
    }
    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        if (mPaint==null){
            initPaint()
        }
//        canvas?.restore()

        val path = Path()
        path.moveTo(0f,0f)
        path.lineTo(0f,mHeight.toFloat())
        path.lineTo(mWidth.toFloat(),mHeight.toFloat())
        path.lineTo(0f,0f)
        canvas?.clipPath(path)
        canvas?.drawColor(Color.RED)

        /*画字*/
        canvas?.rotate(45f)
        canvas?.drawText("已激活",(mWidth*4/9).toFloat(),(mHeight/3).toFloat(),mPaint)
//        canvas?.drawText("已激活",0f,(mHeight/2).toFloat(),mPaint)
        canvas?.rotate(-45f)
//        canvas?.save()
    }
    fun initPaint(){
        mPaint= Paint()
        mPaint?.color=Color.WHITE
        mPaint?.textSize=26f
    }

}